package com.lz.football.module.guide.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.GuideEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.liangzhong.events.TechBarEvent;
	import com.lz.football.module.guide.Guide;
	import com.lz.football.module.main.view.MainView;
	import com.lz.football.module.techBar.view.RoleRefreshPanel;
	import com.lz.football.module.techBar.view.TechBarView;
	
	import common.base.GoodsUsePanel;
	
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import lz.controls.events.ListEvent;
	import lz.controls.managers.AnimationManager;

	/**
	 *自身强化引导 
	 * @author lake
	 * 
	 */	
	public class RoleFreshGuideView extends Guide
	{
		public function RoleFreshGuideView()
		{
			super();
		}
		/**
		 *初始化 
		 */		
		override protected function initView():void
		{
			super.initView();
			initDialog_1();
			//disable
			MainView.shopBtn.mouseEnabled = false;
			MainView.bagBtn.mouseEnabled = false;
		}
		/**
		 * 场景内对话框 
		 *	自身强化
			官方说法：强化自己在比赛中的角色！
			1L：自己上场才是真的足球比赛！
			2L：这个最鸡冻了！
			3L：前提是自己别弱爆。。。
		 * 
		 */		
		private function initDialog_1():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_9");
			GlobalDef.GameWindowContainer.addChild(bgMark);
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn1_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn1_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			TweenLite.delayedCall(.2,getFuncIcon);
		}
		/**
		 *获得按钮
		 */		
		private function getFuncIcon():void
		{
			GlobalDef.GameWindowContainer.addChild(bgMark);
			sceneBtn = Reflection.createInstance("com.football.main.techBtn");
			(sceneBtn as InteractiveObject).mouseEnabled = false;
			MainView.techBtn.visible = false;
			
			var appearMc :MovieClip = Reflection.createInstance("com.football.guide.AppearAtSkin");
			DisplayObjectUtil.removeAllChildren(appearMc.mc.mc);
			appearMc.mc.mc.addChild(sceneBtn);
			sceneBtn.x = -16;
			sceneBtn.y = -14;
			(sceneBtn as InteractiveObject).mouseEnabled = false;
			addDispToStage(appearMc);
			var entP :Point = MainView.techBtn.localToGlobal(new Point(0,0));
			AnimationManager.moveToThing(new Point(appearMc.x,appearMc.y),appearMc,entP,{delay:1,overwrite:0},.5);
			TweenLite.delayedCall(1.5,showFuncIcon);
		}
		/**
		 *显示按钮 
		 * 
		 */		
		private function showFuncIcon():void
		{
			MainView.techBtn.visible = true;
			removeBgMark();
			//限制区域
			var rectPoint :Point = MainView.techBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,MainView.techBtn.width,MainView.techBtn.height);
			step();
			//指向图标按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width/2,curClickRect.y);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,0);
			sceneBtn =  MainView.techBtn;
			arrowAngle = 0;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
		}
		/**
		 *界面显示
		 * @param e
		 * 
		 */		
		private function onLoadResComplete2(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			//限制区域
			var rectPoint :Point = RoleRefreshPanel.freshCardSkin.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,RoleRefreshPanel.freshCardSkin.width,RoleRefreshPanel.freshCardSkin.height);
			step();
			//指向洗练卡
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn =  RoleRefreshPanel.freshCardSkin;
			arrowAngle = -90;
			//事件
			AppEventDispatcher.getInstance().addEventListener("Guide_RoleFresh_Item_C",clickFreshPos);
		}
		/**
		 *点击洗练卡位置 
		 * @param e
		 * 
		 */		
		private function clickFreshPos(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener("Guide_RoleFresh_Item_C",clickFreshPos);
			//限制区域
			var rectPoint :Point = GoodsUsePanel.firstItemSkin.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,GoodsUsePanel.firstItemSkin.width,GoodsUsePanel.firstItemSkin.height);
			step();
			//指向小背包第一格子
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn =  GoodsUsePanel.firstItemSkin;
			arrowAngle = -90;
			//事件
			GlobalDef.GameStage.addEventListener(ListEvent.ITEM_CLICK,itemClickh);
		}
		/**
		 *点击物品 
		 * @param e
		 * 
		 */		
		private function itemClickh(e :Event):void
		{
			GlobalDef.GameStage.removeEventListener(ListEvent.ITEM_CLICK,itemClickh);
			//限制区域
			var rectPoint :Point = GoodsUsePanel.useBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,GoodsUsePanel.useBtn.width,GoodsUsePanel.useBtn.height);
			step();
			//指向使用
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  GoodsUsePanel.useBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener("Guide_use_item",useItemH);
		}
		/**
		 *使用物品 
		 * @param e
		 * 
		 */		
		private function useItemH(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener("Guide_use_item",useItemH);
			//限制区域
			var rectPoint :Point = RoleRefreshPanel.startBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,RoleRefreshPanel.startBtn.width,RoleRefreshPanel.startBtn.height);
			step();
			//指向洗练
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  RoleRefreshPanel.startBtn;
			arrowAngle = 90;
			//事件
			GlobalDef.GameStage.addEventListener(TechBarEvent.ROLE_REFRESH,freshH);
		}
		/**
		 *洗练 
		 * @param e
		 */		
		private function freshH(e :Event):void
		{
			GlobalDef.GameStage.removeEventListener(TechBarEvent.ROLE_REFRESH,freshH);
			//提交引导
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE,{step:6}));
			TweenLite.delayedCall(3.5,initDialog_2);
			removeArrowMc();
		}
		/**
		 * 场景内对话框 
		 *	核心属性
			官方：每个位置的球员核心属性都不相同。
			1L：追逐核心属性最大化！
			2L：能不能6项全满？
			3L：你这是要疯的节奏么？
		 */		
		private function initDialog_2():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_10");
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn2_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn2_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			//限制区域
			var rectPoint :Point = TechBarView.CLoseBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,TechBarView.CLoseBtn.width,TechBarView.CLoseBtn.height);
			step();
			//指向关闭按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width + 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  TechBarView.CLoseBtn;
			arrowAngle = 90;
			//事件
			GlobalDef.GameStage.addEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
		}
		/**
		 *  关闭
		 * @param e
		 * 
		 */		
		private function onRemoveModuleHandler(e :Event):void
		{
			GlobalDef.GameStage.removeEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
			clear();
			//第6步刷新
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE+"_refresh",{step:6}));
			//enable
			MainView.shopBtn.mouseEnabled = true;
			MainView.bagBtn.mouseEnabled = true;
		}
		/**
		 *执行 
		 * 
		 */		
		override public function process():void
		{
			initView();
		}
		/**
		 *清理 
		 * 
		 */		
		override public function clear():void
		{
			if(dialogBtn)
			{
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_Click);
			}
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			AppEventDispatcher.getInstance().removeEventListener("Guide_RoleFresh_Item_C",clickFreshPos);
			GlobalDef.GameStage.removeEventListener(ListEvent.ITEM_CLICK,itemClickh);
			AppEventDispatcher.getInstance().removeEventListener("Guide_use_item",useItemH);
			GlobalDef.GameStage.removeEventListener(TechBarEvent.ROLE_REFRESH,freshH);
			GlobalDef.GameStage.removeEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
			super.clear();
		}
	}
}